package com.yswee.mallnavi;

import com.google.gson.Gson;
import com.yswee.framework.utils.PreferenceUtils;
import com.yswee.mallnavi.entity.Account;
import com.yswee.mallnavi.entity.common.CompanyEntity;


public class Preference {

	private static final String KEY_USER = "user_info";
	private static final String KEY_COMPANY = "company";

	public static CompanyEntity getCompany() {
		CompanyEntity entity = null;
		try {
			String json = PreferenceUtils.getString(KEY_COMPANY);
			Gson gson = new Gson();
			entity = gson.fromJson(json, CompanyEntity.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return entity;
	}
	
	public static void setCompany(CompanyEntity entity) {
		try {
			Gson gson = new Gson();
			String json = gson.toJson(entity, CompanyEntity.class);
			PreferenceUtils.putString(KEY_COMPANY, json);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static Account getUserEntity() {
		Account entity = null;
		try {
			String json = PreferenceUtils.getString(KEY_USER);
			Gson gson = new Gson();
			entity = gson.fromJson(json, Account.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (entity == null) {
			entity = new Account();
		}
		return entity;
	}
	
	public static void setUserEntity(Account entity) {
		try {
			Gson gson = new Gson();
			String json = gson.toJson(entity, Account.class);
			PreferenceUtils.putString(KEY_USER, json);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}	
	
}
